<?php
/*
Plugin Name:  Portal Cache
Plugin URI: http://www.de-sci.org/blogs
Description:  This plugin will update the cache of portal page upon the updating of each blog.
Version: 0.1 
Author: Liu Xuefeng
Author URI: http://www.xys-reader.org/blogs/sys_admin
*/

if(function_exists('add_action')) {
                // Post ID is received
                add_action('publish_post', 'wp_portal_cache', 0);
                add_action('edit_post', 'wp_portal_cache', 0);
                add_action('delete_post', 'wp_portal_cache', 0);
                add_action('publish_phone', 'wp_portal_cache', 0);
                // Coment ID is received
                add_action('trackback_post', 'wp_portal_cache', 0);
                add_action('pingback_post', 'wp_portal_cache', 0);
                add_action('comment_post', 'wp_portal_cache', 0);
                add_action('edit_comment', 'wp_portal_cache', 0);
                add_action('wp_set_comment_status', 'wp_portal_cache', 0);
                // No post_id is available
                add_action('delete_comment', 'wp_portal_cache', 0);
                //add_action('switch_theme', 'wp_portal_cache', 0);
}

function wp_portal_cache($option="part"){

	if($option == "all" ){
	system("wget http://www.de-sci.org/blogs/portal_cache.php?refresh=1 -O ".ABSPATH."/portal_cache.html.part -T 5");	
	}
	else{
	system("wget http://www.de-sci.org/blogs/portal_cache.php -O ".ABSPATH."/portal_cache.html.part -T 5");	
	}
	system("mv ".ABSPATH."/portal_cache.html.part ".ABSPATH."/portal_cache.html ");	

}
